EEL_MODS	+= busybox

# $(subst .,_,$(BB_VERSION)): 1.35.0 -> 1_35_0
BB_TAG		= $(subst .,_,$(BB_VERSION))
$(eval $(call deftargets_git,busybox,BB))
$(eval $(call deftargets_download,busybox,BB,$$(BB_PKG),$$(BB_TAG)))

PHONY-busybox += bb-%
bb-%: $(BUILD_DEPS) $(O_BB_DIR)
	$(EELQ2)$(MAKE) $(JOB_OPT) \
		-C $(S_BB_DIR) \
		ARCH=$(BB_ARCH) \
		CROSS_COMPILE=$(TC_PREFIX) \
		O=$(O_BB_DIR) \
		$(patsubst bb-%,%,$@)

# BusyBox executable file
PHONY-busybox += busybox busybox-install
busybox: $(BUILD_DEPS) $(O_BB_DIR) busybox-prepare
	$(EELQ5)\rm -f $(O_BB_DIR)/.build_done.busybox

	$(EELQ3)$(MAKE_THIS) busybox-defconfig
	$(EELQ2)$(MAKE) $(JOB_OPT) \
		-C $(S_BB_DIR) \
		ARCH=$(BB_ARCH) \
		CROSS_COMPILE=$(TC_PREFIX) \
		O=$(O_BB_DIR) \
		$(BB_TARGETS)

$(O_BB_DIR)/busybox:
	$(EELQ5)$(MAKE_THIS) busybox

busybox-install: $(O_BB_DIR)/busybox
	$(EELQ5)$(MAKE_THIS) bb-install \
		&& touch $(O_BB_DIR)/.build_done.busybox

PHONY-busybox += busybox-defconfig busybox-menuconfig busybox-savedefconfig
busybox-defconfig: bb-$(BB_CONFIG)
busybox-menuconfig: bb-menuconfig
busybox-savedefconfig: $(O_BB_DIR)/.config
	$(EELQ5)mkdir -p $(S_BB_DIR)/configs
	$(EELQ5)mkdir -p $(EEL_CHG_DIR)/$(BB_VER_DIR)/configs
	$(EELQ)cp $(O_BB_DIR)/.config \
		$(S_BB_DIR)/configs/$(BB_SAVECONF)
	$(EELQ)cp $(O_BB_DIR)/.config \
		$(EEL_CHG_DIR)/$(BB_VER_DIR)/configs/$(BB_SAVECONF)

# for BusyBox installed directory $(O_BB_DIR)/_install
$(O_BB_DIR)/.build_done.busybox: $(O_BB_DIR)
	$(EELQ5)$(MAKE_THIS) busybox-install

$(O_BB_DIR):
	$(EELQ5)mkdir -p $@
